package
{
  public class PlayerData
  {
    private static const qb:Object = { major:["Strength", "Stamina", "Vision", "Confidence", "Throwing"],
                             minor:["Speed", "Agility", "Jumping", "Catching", "Carrying"],
                             majorBonus:[40, 30, 23, 17],
                             minorBonus:[20, 15, 11, 08]
                           };

    private static const hb:Object = { major:["Strength", "Speed", "Agility", "Vision", "Confidence", "Carrying"],
                             minor:["Jumping", "Stamina", "Blocking", "Throwing", "Catching"],
                             majorBonus:[33, 25, 19, 14],
                             minorBonus:[20, 15, 11, 08]
                           };


    private static const fb:Object = { major:["Strength", "Blocking", "Agility", "Carrying"],
                             minor:["Stamina", "Vision", "Confidence", "Tackling", "Catching"],
                             majorBonus:[50, 38, 28, 21],
                             minorBonus:[20, 15, 11, 08]
                           };

    private static const wr:Object = { major:["Speed", "Agility", "Jumping", "Stamina", "Vision", "Catching"],
                             minor:["Confidence", "Carrying"],
                             majorBonus:[33, 25, 19, 14],
                             minorBonus:[50, 38, 28, 21]
                           };
                             
    private static const te:Object = { major:["Strength", "Blocking", "Vision", "Catching"],
                             minor:["Speed", "Agility", "Stamina", "Confidence", "Tackling", "Carrying"],
                             majorBonus:[50, 38, 28, 21],
                             minorBonus:[17, 13, 09, 07]
                           };

    private static const oc:Object = { major:["Strength", "Blocking"],
                             minor:["Agility", "Stamina", "Vision", "Confidence", "Tackling"],
                             majorBonus:[100, 75, 56, 42],
                             minorBonus:[20, 15, 11, 08]
                           };

    private static const og:Object = { major:["Strength", "Confidence", "Blocking"],
                             minor:["Agility", "Stamina", "Vision", "Tackling"],
                             majorBonus:[67, 50, 38, 28],
                             minorBonus:[25, 19, 14, 11]
                           };
                           
    private static const ot:Object = { major:["Strength", "Agility", , "Vision", "Confidence", "Blocking"],
                             minor:["Stamina", "Tackling"],
                             majorBonus:[40, 30, 23, 17],
                             minorBonus:[50, 38, 28, 21]
                           };
                             
    private static const dt:Object = { major:["Strength", "Agility", "Tackling"],
                             minor:["Speed", "Stamina", "Vision", "Confidence", "Blocking"],
                             majorBonus:[67, 50, 38, 28],
                             minorBonus:[20, 15, 11, 08]
                           };

    private static const de:Object = { major:["Strength", "Speed", "Agility", "Tackling"],
                             minor:["Jumping", "Stamina", "Vision", "Confidence", "Blocking"],
                             majorBonus:[50, 38, 28, 21],
                             minorBonus:[20, 15, 11, 08]
                           };

    private static const lb:Object = { major:["Strength", "Agility", "Stamina", "Vision", "Confidence", "Tackling"],
                             minor:["Speed", "Jumping", "Blocking", "Catching"],
                             majorBonus:[33, 25, 19, 14],
                             minorBonus:[25, 19, 14, 11]
                           };

    private static const cb:Object = { major:["Speed", "Agility", "Jumping", "Stamina", "Vision", "Catching"],
                             minor:["Strength", "Confidence", "Tackling", "Carrying"],
                             majorBonus:[33, 25, 19, 14],
                             minorBonus:[25, 19, 14, 11]
                           };

    private static const ss:Object = { major:["Strength", "Speed", "Stamina", "Vision", "Tackling"],
                             minor:["Agility", "Jumping", "Confidence", "Blocking", "Catching", "Carrying"],
                             majorBonus:[40, 30, 23, 17],
                             minorBonus:[17, 13, 09, 07]
                           };
                           
    private static const fs:Object = { major:["Speed", "Stamina", "Vision", "Tackling", "Catching"],
                             minor:["Strength", "Agility", "Jumping", "Confidence", "Blocking", "Carrying"],
                             majorBonus:[40, 30, 23, 17],
                             minorBonus:[17, 13, 09, 07]
                           };

    private static const k:Object = { major:["Confidence", "Kicking"],
                             minor:["Strength", "Speed", "Agility", "Jumping", "Vision", "Throwing"],
                             majorBonus:[100, 75, 56, 42],
                             minorBonus:[17, 13, 09, 07]
                           };
                             
    private static const p:Object = { major:["Confidence", "Punting"],
                             minor:["Strength", "Speed", "Agility", "Jumping", "Vision", "Throwing"],
                             majorBonus:[100, 75, 56, 42],
                             minorBonus:[17, 13, 09, 07]
                           };
                           
    [Bindable]
    public var pos:String = "QB";

    [Bindable]
    public var lvl:uint = 1;
    
    [Bindable]
    public var xp:uint = 0;
    
    [Bindable]
    public var tp:uint = 0;

    [Bindable]
    public var sp:uint = 0;

    [Bindable]
    public var ssn:uint = 1;
    
    [Bindable]
    public var bt:uint = 0;

    [Bindable]
    public var day:int = -4;

    [Bindable]
    public var str:uint = 800;

    [Bindable]
    public var spd:uint = 800;

    [Bindable]
    public var agi:uint = 800;

    [Bindable]
    public var jmp:uint = 800;
    
    [Bindable]
    public var sta:uint = 800;

    [Bindable]
    public var vis:uint = 800;

    [Bindable]
    public var con:uint = 800;

    [Bindable]
    public var blk:uint = 800;

    [Bindable]
    public var tak:uint = 800;

    [Bindable]
    public var thr:uint = 800;

    [Bindable]
    public var cth:uint = 800;
    
    [Bindable]
    public var car:uint = 800;
    
    [Bindable]
    public var kck:uint = 800;
    
    [Bindable]
    public var pnt:uint = 800;

    private var position:Object = null;
    
    public static function spCost( n:Number ):uint
    {
      return Math.exp(.0003 * Math.pow(n, 2));
    }

    public function PlayerData():void
    {
      setPosition();
    }
    
    public function copy( pd:PlayerData ):void
    {
      pos = pd.pos;
      lvl = pd.lvl;
      xp  = pd.xp;
      tp  = pd.tp;
      sp  = pd.sp;
      ssn = pd.ssn;
      bt  = pd.bt;
      day = pd.day;
      str = pd.str;
      spd = pd.spd;
      agi = pd.agi;
      jmp = pd.jmp;
      sta = pd.sta;
      vis = pd.vis;
      con = pd.con;
      blk = pd.blk;
      tak = pd.tak;
      thr = pd.thr;
      cth = pd.cth;
      car = pd.car;
      kck = pd.kck;
      pnt = pd.pnt;
      
      setPosition();
    }
    
    public function getStat( s:String ):uint
    {
      switch( s )
      {
        case "Strength":   return str;
        case "Speed":      return spd;
        case "Agility":    return agi;
        case "Jumping":    return jmp;
        case "Stamina":    return sta;
        case "Vision":     return vis;
        case "Strength":   return str;
        case "Confidence": return con;
        case "Blocking":   return blk;
        case "Tackling":   return tak;
        case "Throwing":   return thr;
        case "Catching":   return cth;
        case "Carrying":   return car;
        case "Kicking":    return kck;
        case "Punting":    return pnt;
        default:           return 0;
      }
    }

    public function setStat( s:String, n:uint ):void
    { 
      switch( s )
      {
        case "Strength":   str = n;
                           return;
        case "Speed":      spd = n;
                           return;
        case "Agility":    agi = n;
                           return;
        case "Jumping":    jmp = n;
                           return;
        case "Stamina":    sta = n;
                           return;
        case "Vision":     vis = n;
                           return;
        case "Strength":   str = n;
                           return;
        case "Confidence": con = n;
                           return;
        case "Blocking":   blk = n;
                           return;
        case "Tackling":   tak = n;
                           return;
        case "Throwing":   thr = n;
                           return;
        case "Catching":   cth = n;
                           return;
        case "Carrying":   car = n;
                           return;
        case "Kicking":    kck = n;
                           return;
        case "Punting":    pnt = n;
                           return;
        // Importer Specific
        case "Skill Points":    sp = n;
                                return;
        case "Training Points": tp = n;
                                return;
        case "Bonus Tokens":    bt = n;
                                return;
        case "Level":           lvl = n;
                                return;
        case "Next Level":      xp = n;
                                return;
      }
    }

    public function getDailyXp( n:uint ):uint
    {
      switch ( n )
      {
        case 1:  return 100;
        case 2:  return 96
        case 3:  return 91;
        case 4:  return 87;
        case 5:  return 82;
        case 6:  return 77;
        case 7:  return 73;
        case 8:  return 69;
        case 9:  return 65;
        case 10: return 61;
        case 11: return 57;
        case 12: return 54;
        case 13: return 51;
        case 14: return 47;
        case 15: return 45;
        case 16: return 42;
        case 17: return 39;
        case 18: return 37
        case 19: return 34
        case 20: return 32
        case 21: return 30
        case 22: return 28
        case 23: return 26
        default: return 25;
      }
    }

    public function getGameXp( n:uint ):uint
    {
      switch ( n )
      {
        case 1:  return 568;
        case 2:  return 540
        case 3:  return 514;
        case 4:  return 489;
        case 5:  return 464;
        case 6:  return 439;
        case 7:  return 413;
        case 8:  return 388;
        case 9:  return 364;
        case 10: return 343;
        case 11: return 339;
        case 12: return 304;
        case 13: return 282;
        case 14: return 270;
        case 15: return 253;
        case 16: return 235;
        case 17: return 216;
        case 18: return 205
        case 19: return 191
        case 20: return 194
        case 21: return 179
        case 22: return 160
        case 23: return 147
        case 24: return 139
        case 25: return 130
        case 26: return 117
        case 27: return 113
        case 28: return 106
        default: return 100;
      }
    }
    
    public function setPos( s:String ):void
    {
      pos = s;
      setPosition();
    }
    
    public function setPosition():void
    {
      switch ( pos )
      {
        case "QB": position = qb;
                   return;
        case "HB": position = hb;
                   return;
        case "FB": position = fb;
                   return;
        case "WR": position = wr;
                   return;
        case "TE": position = te;
                   return;
        case "OC": position = oc;
                   return;
        case "OG": position = og;
                   return;
        case "OT": position = ot;
                   return;
        case "DT": position = dt;
                   return;
        case "DE": position = de;
                   return;
        case "LB": position = lb;
                   return;
        case "CB": position = cb;
                   return;
        case "SS": position = ss;
                   return;
        case "FS": position = fs;
                   return;
        case "K":  position = k;
                   return;
        case "P":  position = p;
                   return;
      }
    }
    
    private function checkLvl():uint
    {
      if ( lvl < 22 )
        return 0;
        
      if ( lvl < 30 )
        return 1;
      
      if ( lvl < 38 )
        return 2;
        
      return 3;
    }
    
    public function levelUp():void
    {
      lvl++;
      sp += 5;
      for each ( var major:String in position.major )
        setStat( major, getStat(major) + position.majorBonus[checkLvl()] ); 

      for each ( var minor:String in position.minor )
        setStat( minor, getStat(minor) + position.minorBonus[checkLvl()] ); 
    }
    
    public function checkXp( n:uint ):void
    {
      if ( xp + n > 999 )
      {
        xp = xp + n - 1000;
        levelUp();
      }
      else
        xp += n;
    }
  }
}